package com.springboot.controller.tool;

import com.springboot.service.tool.ToolService;
import com.springboot.util.http.ResponseBuilder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @Classname PdfController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2024/4/25 19:02
 * @Created by zyj
 */
@Controller
@RequestMapping("/pdf")
@Slf4j
@Tag(name = "pdf工具")
public class PdfController {
    @Resource
    private ToolService toolService;


    /**
     * 方法描述
     * type类型  1、替换关键字 2、根据关键字加图片 3、根据坐标添加图片
     * key 关键字
     * value 需要替换关键字的值
     */
    @PostMapping(value = "/createPdf")
    @Operation(description = "操作pdf文件")
    public ResponseEntity<byte[]> createPdf(@RequestParam Map<String, String> params,
                                            @RequestParam(value = "file",required = false) MultipartFile file,
                                            @RequestParam(value = "img",required = false) MultipartFile img){

        try {
            return ResponseBuilder.downFile(String.valueOf(System.currentTimeMillis()), toolService.createPdf(params, file, img), "pdf");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
